const app = getApp()
var netUtil = require("../../utils/netUtil.js"); //require引入
import tool from "../../utils/tools";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '快速报读', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height * 2 + 20,
    // height: app.globalData.height,
    heightTop: app.globalData.height * 2 + 20,
    typesList:[],
    typesIndex:null,
    gradationsList:[],
    gradationsIndex:null,
    schoolsList:[],
    schoolsIndex:null,
    majorsList:[],
    majorsIndex:null,
    classsList:[],
    classsIndex:null,
   payWayList:[{name:'全款',id:0}],
    payWayTab:0,
    totalPrice:0,
    temp:{
      token:'',
      school_specialty_id:'',
      school_class_id:'',
      school_id:'',
      school_type_id:'',
      school_level_id:'',
      school_pay_many_id:'',
      id_name:'',
      id_number:'',
      mobile:'',
      address:'',
      now_address:'',
      first_price:'',
      enroll_address:'',
      enroll_teacher:'',
      city_config_id:'',
      coupon_id:''
    },
    userInfo:'',
    token:'',
    pay_many_price:0,
    provinceList:[],
    cityList:[],
    city:'',
    isCityShow:true,
    indexValue:[0,0],
    isClick:true,
    words:'',
    id:'',
    is_coupon:null,//是否可使用优惠券
    couponName:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //判断在iphoneX和其它机型下按钮位置
    if (app.globalData.isIpx === true) {
      this.setData({
        marginTop: 10
      })
    } else {
      this.setData({
        marginTop:40
      })
    }
    this.isHide()

    const words=options.words?options.words:''
    const id=options.id?options.id:''
    this.setData({
      words:words,
      id:id
    })
  
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (!wx.getStorageSync("userInfo")) {
      wx.showModal({
        title: '提示',
        content: '您还未登录，请先登录',
        success(res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/author/author',
            })
          } else if (res.cancel) {
            wx.switchTab({
              url: '/pages/index/index',
            })
          }
        }
      })
    }else{
      this.setData({      
        token:wx.getStorageSync("token"),
        'temp.token':wx.getStorageSync("token")
      })
      let pages = getCurrentPages();
      let currPage = pages[pages.length - 1];
      if(currPage.data.couponId){
        this.setData({
          "temp.coupon_id":currPage.data.couponId,
          couponName:currPage.data.couponName
        })
        if(this.data.temp.first_price){
          const params={
            school_pay_many_id:this.data.temp.school_pay_many_id,
            school_class_id:this.data.temp.school_class_id,
            first_price:this.data.temp.first_price,
            token:this.data.token,
            coupon_id:this.data.temp.coupon_id
          }
          netUtil.postData('order-pay/getPayManyPrice',params, (datas) => {
            if(datas.code===1){
              this.setData({
                pay_many_price:datas.data.pay_many_price,
                totalPrice:datas.data.total_price
              })
            }else{
              wx.showToast({
                title: datas.msg,
                icon:'none'
              })
            }  
          })
        }
      }else{
        if(this.data.id&&this.data.typesIndex===null){
          this.getSearch()
        }else{     
            this.getTypes()       
            this.getCityList()    
        }   
      }    
    }

  },
  // 选择优惠券
  toCoupon(){
    if(this.data.is_coupon==='null'){
      wx.showToast({
        title: '请将信息填写完整',
        icon:'none'
      })
    }else if(this.data.is_coupon==0){
      wx.showToast({
        title: '暂无可用优惠券',
        icon:'none'
      })
    }else{
      wx.navigateTo({
        url: '/pages/coupon/coupon?isSelect=true',
      })
    }
  },
  // 获取搜索
   getSearch(){
    const that=this
    let params={
      school_id:that.data.id,
      word:that.data.words
    }
    netUtil.postData('school/searchLoad',params, (datas) => {   
      if(datas.code===1){
        netUtil.postData('city-config/parentList','', (cityDatas) => {       
          that.setData({
            provinceList:cityDatas.data.lists,
            cityList: cityDatas.data.lists[0].children
          })
          const city=wx.getStorageSync("city")?wx.getStorageSync("city"):'成都市'    
          const indexValue=[]
          that.data.provinceList.forEach((item,index)=>{
            item.children.forEach((data,indexD)=>{     
              if(data.label===city){
                indexValue.push(index)
                indexValue.push(indexD)
              }
            })
          })
          const cityList=that.data.provinceList[indexValue[0]].children
          that.setData({
            indexValue:indexValue,
            cityList:cityList,
            city:cityList[indexValue[1]].label,
            "temp.city_config_id":cityList[indexValue[1]].value,
            cityId:cityList[indexValue[1]].value,
          })
            //类型
            netUtil.postData('school-type/listAll','', (dataT) => {
              const typesList=dataT.data.lists
              that.setData({
                typesList:typesList
              })
              if(datas.data.school_type_id!==0){
                const typesIndex=typesList.findIndex(itemT=>{
                  return itemT.id==datas.data.school_type_id
                })
                that.setData({
                  typesIndex:typesIndex,
                  "temp.school_type_id":datas.data.school_type_id
                })
                //层次
                // const typeId=this.data.typesList[this.data.typesIndex].id
                // netUtil.postData('school-level/listAll',{school_type_id:typeId}, (dataL) => {
                //   const gradationsList=dataL.data.lists
                //   that.setData({
                //     gradationsList:gradationsList,
                //   })
                //   if(datas.data.school_level_id!==0){
                //     const gradationsIndex=gradationsList.findIndex(itemL=>{
                //       return itemL.id==datas.data.school_level_id
                //     })
                //     that.setData({
                //       gradationsIndex:gradationsIndex,
                //       "temp.school_level_id":datas.data.school_level_id
                //     })
                //学校
                const typeId=this.data.typesList[this.data.typesIndex].id
                netUtil.postData('school/listAll',{school_type_id:typeId,city_config_id:this.data.cityId}, (dataS) => {
                  const schoolsList=dataS.data.lists
                  that.setData({
                    schoolsList:schoolsList
                  })
                  if(datas.data.school_id!==0){
                    const schoolsIndex=schoolsList.findIndex(itemS=>{
                      return itemS.id==datas.data.school_id
                    })
                    that.setData({
                      schoolsIndex:schoolsIndex,
                      "temp.school_id":datas.data.school_id
                    })
                // 层次
                const schoolId=this.data.schoolsList[this.data.schoolsIndex].id
                netUtil.postData('school-level/listAll',{school_id:schoolId}, (dataL) => {
                  const gradationsList=dataL.data.lists
                  that.setData({
                    gradationsList:gradationsList,
                  })
                  if(datas.data.school_level_id!==0){
                    const gradationsIndex=gradationsList.findIndex(itemL=>{
                      return itemL.id==datas.data.school_level_id
                    })
                    that.setData({
                      gradationsIndex:gradationsIndex,
                      "temp.school_level_id":datas.data.school_level_id
                    })
                        //专业
                        const levelId=this.data.gradationsList[this.data.gradationsIndex].id
                        netUtil.postData('school-specialty/listAll',{school_level_id:levelId}, (dataM) => {
                          const majorsList=dataM.data.lists
                          that.setData({
                            majorsList:majorsList
                          })
                          if(datas.data.school_specialty_id!==0){
                            const majorsIndex=majorsList.findIndex(itemM=>{
                              return itemM.id==datas.data.school_specialty_id
                            })
                            that.setData({
                              majorsIndex:majorsIndex,
                              "temp.school_specialty_id":datas.data.school_specialty_id
                            })
                            // 班级
                            this.getClass()
                          }
                        })
                      }
                    })
                  }
                })

              }
             

            })
          // }
        })
      }  

    })
  },

  isCityShowTap(){
    this.setData({
      isCityShow:false
    })
  },
  isCityShowHide(){
    this.setData({
      isCityShow:true
    })
  },
  bindChange(e){
    const val = e.detail.value
    this.setData({
      cityList:this.data.provinceList[val[0]].children,
      indexValue:val
    })
  },
  // 选择城市
  citySure(){
    this.setData({
      city:this.data.cityList[this.data.indexValue[1]].label,
      isCityShow:true,
      cityId:this.data.cityList[this.data.indexValue[1]].value,
      schoolsList:[],
      schoolsIndex:null,
      majorsList:[],
      majorsIndex:null,
      classsList:[],
      classsIndex:null,
      is_coupon:null,
      couponName:'',
      "temp.coupon_id":''
    })
    if(this.data.typesIndex&&this.data.gradationsIndex){
      this.getSchools()
    }
    
  },
    // 获取城市
    getCityList(){
      netUtil.postData('city-config/parentList','', (datas) => {
        this.setData({
          provinceList:datas.data.lists,
          cityList: datas.data.lists[0].children
        })
      })
    },
  // 点击支付
  toPayTap: tool.debounce(function(){
    if(!this.data.isClick) return
    wx.showLoading({
      title: '加载中',
    })
    // toPayTaptool.debounce(function() 
    const temp=this.data.temp
    if(temp.school_pay_many_id===0){
      temp.first_price=this.data.totalPrice
    }
    console.log(this.data.cityId)
    if(this.data.cityId){
      temp.city_config_id=this.data.cityId
    }

    netUtil.postData('order-pay/edit',temp, (datas) => {
      if(datas.code===1){
       this.setData({
        isClick:false
       })
        this.payoff(datas.data.order_number,datas.data.order_pay_id)
      }else{
        wx.hideLoading()
        wx.showToast({
          title: datas.msg,
          icon:'none'
        })
      }
    })
  }),
  // 发起支付
  payoff(order_number,order_pay_id){
    const that=this
    const params={
      order_number:order_number,
      token:that.data.token
    }
    netUtil.postData('order/pay',params, (datas) => {
     
      if(datas.code===1){
        wx.hideLoading()
        wx.requestPayment({
          timeStamp: datas.data.timeStamp,
          nonceStr: datas.data.nonceStr,
          package: datas.data.package,
          signType: datas.data.signType,
          paySign: datas.data.paySign,
          success(res) { 
            that.setData({
              isClick:true
             })
            wx.navigateTo({
              url: '/pages/paySuccess/paySuccess?order_pay_id=' + order_pay_id,
            })
          },
          fail(res) { 
            that.setData({
              isClick:true
             })
          }
        })
      }else{
        that.setData({
          isClick:true
         })
        wx.hideLoading()
        wx.showToast({
          title: datas.msg,
          icon:'none'
        })
      }
    })
  },
  // 获取分类
  getTypes(){
    netUtil.postData('school-type/listAll','', (datas) => {
      this.setData({
        typesList:datas.data.lists
      })
    })
  },
  typesChange(e){
    this.setData({
      typesIndex:e.detail.value,
      gradationsList:[],
      gradationsIndex:null,
      schoolsList:[],
      schoolsIndex:null,
      majorsList:[],
      majorsIndex:null,
      classsList:[],
      classsIndex:null,
      payWayList:[{name:'全款'},{name:'分6期'},{name:'分12期'}],
      payWayTab:0,
      'temp.school_type_id':this.data.typesList[e.detail.value].id,
      is_coupon:null,
      couponName:'',
      "temp.coupon_id":''
    })
    this.getSchools()
  //  this.getGradations()
  },

// 获取学校
getSchools(){
  const typeId=this.data.typesList[this.data.typesIndex].id
  // const levelId=this.data.gradationsList[this.data.gradationsIndex].id
  netUtil.postData('school/listAll',{ school_type_id:typeId,city_config_id:this.data.cityId}, (datas) => {
    this.setData({
      schoolsList:datas.data.lists
    })
  })
},
schoolsChange(e){
  this.setData({
    schoolsIndex:e.detail.value,
    gradationsList:[],
    gradationsIndex:null,
    majorsList:[],
    majorsIndex:null,
    classsList:[],
    classsIndex:null,
    payWayList:[{name:'全款'},{name:'分6期'},{name:'分12期'}],
    payWayTab:0,
    'temp.school_id':this.data.schoolsList[e.detail.value].id,
    is_coupon:null,
    couponName:'',
    "temp.coupon_id":''
  })
  this.getGradations()
  // this.getMajor()
},
  // 获取层次
  getGradations(){
    const schoolId=this.data.schoolsList[this.data.schoolsIndex].id
    // const levelId=this.data.gradationsList[this.data.gradationsIndex].id
    // const typeId=this.data.typesList[this.data.typesIndex].id
    netUtil.postData('school-level/listAll',{school_id:schoolId,}, (datas) => {
      this.setData({
        gradationsList:datas.data.lists
      })
    })
  },
  gradationsChange(e){
    this.setData({
      gradationsIndex:e.detail.value,
      // schoolsList:[],
      // schoolsIndex:null,
      majorsList:[],
      majorsIndex:null,
      classsList:[],
      classsIndex:null,
      payWayList:[{name:'全款'},{name:'分6期'},{name:'分12期'}],
      payWayTab:0,
      'temp.school_level_id':this.data.gradationsList[e.detail.value].id,
      is_coupon:null,
      couponName:'',
      "temp.coupon_id":''
    })
    // this.getSchools()
    this.getMajor()
  },
// 获取专业
getMajor(){
  const levelId=this.data.gradationsList[this.data.gradationsIndex].id
  // const schoolId=this.data.schoolsList[this.data.schoolsIndex].id
  netUtil.postData('school-specialty/listAll',{school_level_id:levelId}, (datas) => {
    this.setData({
      majorsList:datas.data.lists
    })
  })
},
majorsChange(e){
  this.setData({
    majorsIndex:e.detail.value,
    classsList:[],
    classsIndex:null,
    payWayList:[{name:'全款'},{name:'分6期'},{name:'分12期'}],
    payWayTab:0,
    'temp.school_specialty_id':this.data.majorsList[e.detail.value].id,
    is_coupon:null,
    couponName:'',
    "temp.coupon_id":''
  })
  this.getClass()
},
// 获取班级
getClass(){
  const specialtyId=this.data.majorsList[this.data.majorsIndex].id
  netUtil.postData('school-class/listAll',{school_specialty_id:specialtyId}, (datas) => {
    this.setData({
      classsList:datas.data.lists
    })
  })
},
classChange(e){
  this.setData({
    classsIndex:e.detail.value,
    payWayList:[{name:'全款'},{name:'分6期'},{name:'分12期'}],
    payWayTab:0,
    'temp.school_class_id':this.data.classsList[e.detail.value].id,
    is_coupon:null,
    couponName:'',
    "temp.coupon_id":''
  })
  this.getPayWay()
},
// 获取分期方案
getPayWay(){
  const classId=this.data.classsList[this.data.classsIndex].id
  netUtil.postData('school-pay-many/listAll',{school_class_id:classId}, (datas) => {
    this.setData({
      is_coupon:datas.data.is_coupon,
      payWayList:datas.data.lists,
      totalPrice:datas.data.lists[this.data.payWayTab].price,
      'temp.school_pay_many_id':datas.data.lists[this.data.payWayTab].id
    })
  })
},
// 选择付款方式
payWayChange(e){
  this.setData({
    payWayTab:e.currentTarget.dataset.current,
    totalPrice:this.data.payWayList[0].price,
    'temp.school_pay_many_id':this.data.payWayList[e.currentTarget.dataset.current].id
  })
  if(this.data.temp.first_price&&this.data.temp.school_class_id&&this.data.temp.school_pay_many_id!=0){
    const params={
      school_pay_many_id:this.data.temp.school_pay_many_id,
      school_class_id:this.data.temp.school_class_id,
      first_price:this.data.temp.first_price,
      token:this.data.token
    }
    netUtil.postData('order-pay/getPayManyPrice',params, (datas) => {
      if(datas.code===1){
        this.setData({
          pay_many_price:datas.data.pay_many_price,
          totalPrice:datas.data.total_price
        })
      }else{
        wx.showToast({
          title: datas.msg,
          icon:'none'
        })
      }  
    })
  }
},
// 获取分期金额
getPayments(e){
  this.setData({
    'temp.first_price':e.detail.value
  })
  if(this.data.temp.school_class_id===''){
    wx.showToast({
      title: '请完善信息',
      icon:'none'
    })
    return
  }
  const params={
    school_pay_many_id:this.data.temp.school_pay_many_id,
    school_class_id:this.data.temp.school_class_id,
    first_price:this.data.temp.first_price,
    token:this.data.token,
    coupon_id:this.data.temp.coupon_id
  }
  netUtil.postData('order-pay/getPayManyPrice',params, (datas) => {
    if(datas.code===1){
      this.setData({
        pay_many_price:datas.data.pay_many_price,
        totalPrice:datas.data.total_price
      })
    }else{
      wx.showToast({
        title: datas.msg,
        icon:'none'
      })
    }  
  })
},
// 获取输入框值
getIdName(e){
  this.setData({
    'temp.id_name':e.detail.value
  })
},
getIdNumber(e){
  this.setData({
    'temp.id_number':e.detail.value
  })
},
getMobile(e){
  this.setData({
    'temp.mobile':e.detail.value
  })
},
getAddress(e){
  this.setData({
    'temp.address':e.detail.value
  })
},
getNowAddress(e){
  this.setData({
    'temp.now_address':e.detail.value
  })
},
getEnrollAddress(e){
  this.setData({
    'temp.enroll_address':e.detail.value
  })
},
getEnrollTeacher(e){
  this.setData({
    'temp.enroll_teacher':e.detail.value
  })
},


// ---------------------------

  // 隐藏支付方式
  isHide(){
    this.setData({
      flag:true
    })
  },
  // 获取证书
  getCertificate(){   
    netUtil.postData('/certificate-list-all','', (datas) => {
      if (this.data.fromdetail === 1 && this.data.thisType===1){ //详情过来
         
        datas.data.lists.forEach((res,index)=>{         
          if (res.id === this.data.detailId*1){           
            this.setData({
              certificateList: datas.data.lists,
              certificateIndex: index,
              allPrice: datas.data.lists[index].price,
              gradaceIndex:0
            })
            this.gradaCe();
          }
        })
      }else{//直接过来
        this.setData({
          certificateList: datas.data.lists,
          certificateIndex: 0,
          allPrice: datas.data.lists[0].price,
          gradaceIndex:0
        })
        this.gradaCe();
      }           
    })
    
  },
  // 展示证书层次
  gradaCe(){
    // 判断当前证书有没有层次
    if (!this.data.certificateList[this.data.certificateIndex].levelList_show || !this.data.certificateList[this.data.certificateIndex].levelList_show.levels){
      
      this.setData({
        isGradation: false,
        gradaceList: []
      })
      this.majorCe()
   }else{
     
      this.setData({
        isGradation: true,
        gradaceList: this.data.certificateList[this.data.certificateIndex].levelList_show.levels,
        gradaceIndex: this.data.gradaceIndex,
        majorCeIndex: 0
      })
      this.majorCe()
   }

  },
  // 选择证书的层次
  gradaceChange(e){
    this.setData({
      gradaceIndex: e.detail.value,
      majorCeIndex: 0
    })
    this.gradaCe();
  },
  // 展示专业
  majorCe(){      
     // 判断当前证书当前层次有没有专业    
    if (!this.data.certificateList[this.data.certificateIndex].levelList_show || !this.data.certificateList[this.data.certificateIndex].levelList_show.levels) {     
      this.setData({
        majorCeList: [],
        isMajorCe: false,
        allPrice: this.data.certificateList[this.data.certificateIndex].price
      })
    } else if (!this.data.certificateList[this.data.certificateIndex].levelList_show.professions[this.data.gradaceIndex].profession_show){     
      this.setData({
        majorCeList: [],
        isMajorCe: false,
        allPrice: this.data.certificateList[this.data.certificateIndex].price
      })
    }else{
      this.setData({
        majorCeList: this.data.certificateList[this.data.certificateIndex].levelList_show.professions[this.data.gradaceIndex].profession_show,
        majorCeIndex: this.data.majorCeIndex,
        isMajorCe: true,
        allPrice: this.data.certificateList[this.data.certificateIndex].levelList_show.professions[this.data.gradaceIndex].price
      })
    }
  },
// 选择证书的专业
  majorCeChange(e){
   
    this.setData({
      majorCeIndex: e.detail.value
    })
    
    this.majorCe();
  },
  // 选择证书
  certificateChange(e){
    var that = this;
    this.setData({
      certificateIndex: e.detail.value     
    })
    this.setData({
      // allPrice: this.data.certificateList[e.detail.value ].price,
      payWayTab:0
    })
    this.gradaCe();
  },
  // 获取学校
  getSchool(){
    var that=this
    netUtil.postData('/school-list', '', (datas) => {    
      if (this.data.fromdetail === 1 && this.data.thisType === 0){//详情过来
        datas.data.lists.forEach((res, index) => {
          if (res.id === this.data.detailId * 1) {
            that.setData({
              schoolIndex: index
            })
          }
        })
      }else{
        that.setData({
          schoolIndex: 0
        })
      }
      console.log(that.data.schoolIndex)

      that.setData({
        schoolList: datas.data.lists,
        schoolId: datas.data.lists[that.data.schoolIndex].id
      })


      // 类型
      let typelist=[]
      if (that.data.schoolList[that.data.schoolIndex].is_small==="1"){
        typelist.push({ id: '1', name: '专科' })             
      }
      if (that.data.schoolList[that.data.schoolIndex].is_big === "1"){
        typelist.push({ id: '2', name: '本科' })        
      }    
      that.setData({
        typeList: typelist,
        typeIndex: 0,
        typeId: typelist[0].id,
      })
      
      // 专业
      if (that.data.typeList[that.data.typeIndex].name==="本科"){
       
        that.setData({
          majorList: that.data.schoolList[that.data.schoolIndex].big_grade_show,          
          classList: that.data.schoolList[that.data.schoolIndex].big_grade_model_show,
          allPrice: that.data.schoolList[that.data.schoolIndex].big_price
        })
      }else{       
        that.setData({
          majorList: that.data.schoolList[that.data.schoolIndex].small_grade_show,        
          classList: that.data.schoolList[that.data.schoolIndex].small_grade_model_show,
          allPrice: that.data.schoolList[that.data.schoolIndex].small_price,        
        })
        console.log(that.data.majorList)
      }

      this.setData({
        majorIndex: 0,
        classType: this.data.classList[0],
        major: this.data.majorList[0]
      })

    })
  },
  // 获取年份
  getYear(){
    netUtil.postData('/year-list','', (datas) => {   
      this.setData({
        yearList: datas.data.lists
      })
    })
  },
  yearChange(e){
    this.setData({
      yearIndex: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  
  // 去支付
  toPay(){
 
     // is_valid=1表示已认证 0没认证
    if (this.data.userInfo.is_valid === 0){
     
      wx.showToast({
        title: '您还没实名认证，请先实名认证',
        icon:'none'
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/pages/realName/realName',
        })
      },1000)
    }


    if (this.verification()===false) return
   
    if (this.data.payWay ==='全款'){
      this.setData({
        payWay:1
      })
    }else{
      this.setData({
        payWay:2
      })
    }
    let params={}
    let url={}
    if (this.data.currentTab===0){//学校
       params = {
        // token: this.data.userInfo.token,
        school_id: this.data.schoolId,
        small_or_big: this.data.typeId,
        grade_model: this.data.classType,
        school_grade: this.data.major,
        stage: this.data.payWay,
        id_name: this.data.name,
        id_number: this.data.idNum,
        mobile: this.data.tel,
        run_people_mobile:this.data.jbTel,
         year: this.data.yearList[this.data.yearIndex],
         email: this.data.email,
         address: this.data.address 
      }
      url ='/submit-order'
    }else{//证书
       params = {
        // token: this.data.userInfo.token,
        id: this.data.certificateList[this.data.certificateIndex].id,
        level: this.data.gradaceList[this.data.gradaceIndex],
        school_grade: this.data.majorCeList[this.data.majorCeIndex],
        stage: this.data.payWay,
        id_name: this.data.name,
        id_number: this.data.idNum,
        mobile: this.data.tel,
        run_people_mobile: this.data.jbTel
      }
      url = '/submit-certificate-order'
    }
    
    console.log(params)
    this.setData({
      flag: false,
      payData: JSON.stringify(params),//传入支付方式组件
      url: url
    })
    
  },
  // 验证
  verification(){
    if (!this.data.name){
      wx.showToast({
        title: '请填写真实姓名',
        icon:'none'
      })
      return false
    } else if (!this.data.idNum){
      wx.showToast({
        title: '请填写证件号码',
        icon: 'none'
      })
      return false
    } else if (!this.data.tel) {
      wx.showToast({
        title: '请填写联系电话',
        icon: 'none'
      })
      return false
    } else if (!this.data.email){
      wx.showToast({
        title: '请填写邮箱',
        icon: 'none'
      })
      return false
    }
    return true
  },
  // 名字
  getName(e){
    this.setData({
      name: e.detail.value
    })
  },
  // 证件号
  getIdNum(e){
    this.setData({
      idNum: e.detail.value
    })
  },
  // 电话
  getTel(e){
    this.setData({
      tel: e.detail.value
    })
  },
  //经办人电话
  getJbTel(e){
    this.setData({
      jbTel: e.detail.value
    })
  },
  // 过去邮箱
  getEmail(e){
    this.setData({
      email: e.detail.value
    })
  },

  //方式点击切换
  stateTab: function (e) {
    
    var that = this;   
      this.setData({
        currentTab: e.target.dataset.current,
        payWayTab:0
      })
    if (this.data.currentTab === 1) {
      this.getCertificate();
    }else{
      this.getSchool();
    }
  },
  // 班型切换
  classWay(e){ 
    var that = this;
    if (this.data.classTab === e.target.dataset.current) {
      return false;
    } else {
      this.setData({
        classTab: e.target.dataset.current,
        classType: e.currentTarget.dataset.item
      })
    }
  },
  //付款方式点击切换
  payWay: function (e) {
    var that = this;
    if (this.data.payWayTab === e.target.dataset.current) {
      return false;
    } else {
      this.setData({
        payWayTab: e.target.dataset.current,
        payWay: e.currentTarget.dataset.item
      })
    }
    if (e.target.dataset.current===0){//0期
      if (that.data.currentTab===0){//学校
      
        // 专业 班型  价格
        if (this.data.typeList[this.data.typeIndex].name === "本科") {
          this.setData({
            allPrice: this.data.schoolList[this.data.schoolIndex].big_price,
            
          })
        } else {
          this.setData({
            allPrice: this.data.schoolList[this.data.schoolIndex].small_price,
            
          })
        }  
      }else{//证书
        
        this.setData({
          allPrice: this.data.certificateList[this.data.certificateIndex].price
        })
      }
          
    } else {//12期
      if (that.data.currentTab === 0) {//学校
        if (this.data.typeList[this.data.typeIndex].name === "本科") {
          this.setData({
            allPrice: this.data.schoolList[this.data.schoolIndex].big_twelve_price,
            onePrice: this.data.schoolList[this.data.schoolIndex].big_twelve_price_one
          })
        } else {
          this.setData({
            allPrice: this.data.schoolList[this.data.schoolIndex].small_twelve_price,
            onePrice: this.data.schoolList[this.data.schoolIndex].small_twelve_price_one
          })
        }
      }else{
       
        this.setData({
          allPrice: this.data.certificateList[this.data.certificateIndex].twelve_price
        })
      }
      
    }
  },
  // 选择层次
  typeChange(e){
    this.setData({
      typeIndex: e.detail.value,
      typeId: this.data.typeList[e.detail.value].id
    })

    // 专业 班型  价格
    if (this.data.typeList[this.data.typeIndex].name === "本科") {
      this.setData({
        majorList: this.data.schoolList[this.data.schoolIndex].big_grade_show,
        classList: this.data.schoolList[this.data.schoolIndex].big_grade_model_show,
        allPrice: this.data.schoolList[this.data.schoolIndex].big_price
      })
    } else {
      this.setData({
        majorList: this.data.schoolList[this.data.schoolIndex].small_grade_show,
        classList: this.data.schoolList[this.data.schoolIndex].small_grade_model_show,
        allPrice: this.data.schoolList[this.data.schoolIndex].small_price
      })
    }
    this.setData({
      classType: this.data.classList[0],
      major: this.data.majorList[0]
    })

  },
  // 选择学校
  schoolChange: function (e) {   
    this.setData({
      schoolIndex: e.detail.value,
      schoolId: this.data.schoolList[e.detail.value].id,
      payWayTab: 0
    })

    // 类型
    let typelist = []
    if (this.data.schoolList[this.data.schoolIndex].is_small === "1") {
      typelist.push({ id: '1', name: '专科' })
    }
    if (this.data.schoolList[this.data.schoolIndex].is_big === "1") {
      typelist.push({ id: '2', name: '本科' })
    }
    this.setData({
      typeList: typelist,
      typeIndex: 0,
      typeId: typelist[0].id,
    })
    
    // 专业 班型  价格
    if (this.data.typeList[this.data.typeIndex].name === "本科") {
      this.setData({
        majorList: this.data.schoolList[this.data.schoolIndex].big_grade_show,
        classList: this.data.schoolList[this.data.schoolIndex].big_grade_model_show,
        allPrice: this.data.schoolList[this.data.schoolIndex].big_price
      })
    } else {     
      this.setData({
        majorList: this.data.schoolList[this.data.schoolIndex].small_grade_show,     
        classList: this.data.schoolList[this.data.schoolIndex].small_grade_model_show,
        allPrice: this.data.schoolList[this.data.schoolIndex].small_price
      })
    }
    this.setData({
      classType: this.data.classList[0],
      major: this.data.majorList[0]
    })


  },

  // 选择省市区函数
  changeRegin(e) {
    this.setData({ region: e.detail.value });
  },
  // 选择二级联动
  changeMultiPicker(e) {
    this.setData({ multiIndex: e.detail.value })
  },
  // 选择三级联动
  changeMultiPicker3(e) {
    this.setData({ multiIndex3: e.detail.value })
  },
  
  
  // 选择专业
  majorChange(e) {
    this.setData({
      majorIndex: e.detail.value,
      major: this.data.majorList[e.detail.value]
    })
    
  },
  goBack(){
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})